/**
 * author:Administrator
 * date:2015/7/27
 * desc:TODO
 */

'use strict';

var Router = require('koa-router');
var config = require('../../../config/config.js');
let daoDispatcher = require('../../../dao/permission.js');

console.log('router:' + config.baseUrl + '/v2/permission');
var router = new Router({
    prefix: config.baseUrl + '/v2/permission'
});

module.exports = router.routes();


/***
 * 添加权限, 并非向某个角色添加权限
 * post /o2o/api/permission/v2/batch
 {
    "商家管理": ["添加商家","编辑商家"],
    "商家详情": ["商家详情","编辑店面","添加特惠商品","编辑特惠商品","评价管理"],
    "店面管理": ["编辑店面"],
    "特惠商品管理": ["编辑特惠商品"],
    "订单管理": ["订单详情"],
    "退款管理": ["查看退款"],
    "用户管理": ["交易管理"],
    "优惠券管理": ["添加优惠券","编辑优惠券","领取记录"],
    "专题活动管理": ["添加专题","编辑专题"],
    "消息管理": ["添加消息","再次发送"],
    "后台使用管理": ["后台角色权限","权限设置"],
    "结算管理": ["结算记录","结算处理"]
 }
 */

router.post('/batch', function*() {
    let result = yield daoDispatcher.addBatch(this.request.inParams);
    this.body = result;
});


/**
 * 获取所有权限列表
 * get /o2o/api/permission/v1/all
 */
router.get('/all', function*() {
    let result = yield daoDispatcher.getAll();
    this.body = result;
});

